<?php
/**
 * Reference fields form
 * @copyright &copy; 2009 The Open University
 * @author j.platts@open.ac.uk
 * @author Author_Name_2@open.ac.uk
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package refworks
 */

GLOBAL $CFG;
require_once($CFG->libdir.'/formslib.php');
//reference edit base form
class refworks_managerefs_form extends moodleform {
    public static $showtoggle = false; //flag for link to show/hide extra fields
    //names of all the possible reference types
    public static $reftypes = array(
            'Abstract',
            'Artwork',
            'Bills/Resolutions',
            'Book, Edited',
            'Book, Section',
            'Book, Whole',
            'Case/Court Decisions',
            'Computer Program',
            'Conference Proceedings',
            'Dissertation/Thesis',
            'Dissertation/Thesis Unpublished',
            'Generic',
            'Grant',
            'Hearing',
            'Journal Article',
            'Journal, Electronic',
            'Laws/Statutes',
            'Magazine Article',
            'Map',
            'Monograph',
            'Motion Picture',
            'Music Score',
            'Newspaper Article',
            'Online Discussion Forum/Blogs',
            'Patent',
            'Personal Communication',
            'Report',
            'Sound Recording',
            'Unpublished Material',
            'Video/DVD',
            'Web Page'
            );

     //supported field names (names should match names of fields in form)
     public static $reffields = array(
         'rt',
         'a1',
         't1',
         't2',
         'jf',
         'sr',
         'yr',
         'rd',
     	 'fd',
         'vo',
         'ed',
         'is',
         'sp',
         'op',
         'pb',
         'pp',
         'a2',
         'sn',
         'do',
         'ul',
     	'u1',
        'u2',
         'u3',
         'u5',
         'no'
     );

            function definition() {

                $mform    =& $this->_form;

                //-------------------------------------------------------------------------------
                // Add General box
                //$mform->addElement('header', 'general', get_string('general', 'form'));

                //REF TYPE (rt)
                $mform->addElement('select', 'rt', get_string('form_reftype', 'refworks'), self::$reftypes);

                if(refworks_managerefs_form::$showtoggle==true){
                    $mform->addElement('html', '<div class="mrefformcontainer" id="createref_container_toggle">');
                    $mform->addElement('html', '</div>');
                }

                //DOI array

                $mform->addElement('html', '<div class="mrefformcontainer" id="container_doi">');
                $mform->registerNoSubmitButton('get_data');
                $doiarray=array();
                $doiarray[] =& $mform->createElement('text', 'do', get_string('form_doi', 'refworks'));
                $doiarray[] =& $mform->createElement('submit','get_data',get_string('form_doi_get', 'refworks'));
                $mform->addGroup($doiarray, 'doiarray', get_string('form_doi', 'refworks'), '', false);
                $mform->setType('do', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                 //ISBN array
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_isbn">');
                $mform->registerNoSubmitButton('get_data_isbn');
                $isbnarray=array();
                $isbnarray[] =& $mform->createElement('text', 'sn', get_string('form_isbn', 'refworks'));
                $isbnarray[] =& $mform->createElement('submit','get_data_isbn',get_string('form_isbn_get', 'refworks'));
                $mform->addGroup($isbnarray, 'isbnarray', get_string('form_isbn', 'refworks'), '', false);
                $mform->setType('sn', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //Source type
                $sourcetypes = array(
                	'Electronic(1)' => get_string('form_sourcetype1', 'refworks'),
                    'Print(0)' => get_string('form_sourcetype0', 'refworks'),
                );
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_sourcetype">');
                $mform->addElement('select', 'sr', get_string('form_sourcetype', 'refworks'), $sourcetypes);
                $mform->addElement('html', '</div>');

                //AUTHORS (a1)*
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_authors">');
                $mform->addElement('text', 'a1', get_string('form_authors', 'refworks'));
                $mform->setType('a1', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //editor (a2)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_editor">');
                $mform->addElement('text', 'a2', get_string('form_editor', 'refworks'));
                $mform->setType('a2', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //Pub Year (yr)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_year">');
                $mform->addElement('text', 'yr', get_string('form_year', 'refworks'));
                $mform->setType('yr', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //TITLE (t1)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_title">');
                $mform->addElement('text', 't1', get_string('form_title', 'refworks'));
                $mform->setType('t1', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //TITLE2 (t2)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_title2">');
                $mform->addElement('text', 't2', get_string('form_title2', 'refworks'));
                $mform->setType('t2', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //Periodical, Full (jf)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_periodical">');
                $mform->addElement('text', 'jf', get_string('form_periodical', 'refworks'));
                $mform->setType('jf', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //Volume (vo)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_volume">');
                $mform->addElement('text', 'vo', get_string('form_volume', 'refworks'));
                $mform->setType('vo', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //edition (ed)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_edition">');
                $mform->addElement('text', 'ed', get_string('form_edition', 'refworks'));
                $mform->setType('ed', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //Issue (is)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_issue">');
                $mform->addElement('text', 'is', get_string('form_issue', 'refworks'));
                $mform->setType('is', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //Start page/total pages (sp)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_page">');
                $mform->addElement('text', 'sp', get_string('form_page', 'refworks'));
                $mform->setType('sp', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //Other page (op)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_otherpage">');
                $mform->addElement('text', 'op', get_string('form_otherpage', 'refworks'));
                $mform->setType('op', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //place of pub (pp)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_placepub">');
                $mform->addElement('text', 'pp', get_string('form_placepub', 'refworks'));
                $mform->setType('pp', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //publisher (pb)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_publisher">');
                $mform->addElement('text', 'pb', get_string('form_publisher', 'refworks'));
                $mform->setType('pb', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //Pub Date Free From (fd) added for Newspaper Article
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_pub_date_free">');
                $mform->addElement('text', 'fd', get_string('form_pub_date_free', 'refworks'));
                $mform->setType('fd', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //url (ul)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_url">');
                $mform->addElement('text', 'ul', get_string('form_url', 'refworks'));
                $mform->setType('ul', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //Date retrieved (rd)
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_retrieved">');
                $mform->addElement('text', 'rd', get_string('form_retrieved', 'refworks'));
                $mform->setType('rd', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                //OU specific fields
                //$mform->addElement('header', 'general', get_string('form_OU', 'refworks'));
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_u1">');
                $mform->addElement('text', 'u1', get_string('form_u1', 'refworks'));
                $mform->setType('u1', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                $mform->addElement('html', '<div class="mrefformcontainer" id="container_u2">');
                $mform->addElement('text', 'u2', get_string('form_u2', 'refworks'));
                $mform->setType('u2', PARAM_TEXT);
                $mform->addElement('html', '</div>');

                $mform->addElement('html', '<div class="mrefformcontainer" id="container_u3">');
                $mform->addElement('text', 'u3', get_string('form_u3', 'refworks'));
                $mform->setType('u3', PARAM_TEXT);
				$mform->addElement('html', '</div>');

                //u5 - url override (staff cap only)
                if(refworks_base::check_capabilities('mod/refworks:allow_url_override')){
                    $mform->addElement('html', '<div class="mrefformcontainer" id="container_u5">');
                    $mform->addElement('text', 'u5', get_string('form_u5', 'refworks'));
                    $mform->setType('u5', PARAM_TEXT);
                    $mform->addElement('html', '</div>');
                }else{
                    $mform->addElement('hidden', 'u5', '');
                }


                //Notes field
                $mform->addElement('html', '<div class="mrefformcontainer" id="container_no">');
                $mform->addElement('textarea', 'no', get_string('form_no', 'refworks'));
                $mform->setType('no', PARAM_TEXT);
                $mform->addElement('html', '</div>');
            }
}
?>